@echo off

REM Notice: This file is overwritten for each patch for safety reasons.
REM         Hence, any manual changes will be overwritten by the next patch.

REM ============ AVOID CHANGES HERE ============

REM SCRIPT_SANITY_BEGIN
echo ERROR: This file needs postprocessing. Run the script to generate it.
exit
REM SCRIPT_SANITY_END
REM DOMAIN_CHECK_BEGIN
SET perr1=1
SET perr2=1
SET perr3=1
SET perr4=1
SET perr5=1

setlocal EnableDelayedExpansion
FOR /f "delims=" %%i IN ('ping -n 1 -w 1 UNKNOWN_DOMAIN') DO (
	echo %%i | find "[0.0.0.0]" >nul
	IF !ERRORLEVEL! EQU 0 SET "perr1=0"
	echo %%i | find "could not find host" >nul
	IF !ERRORLEVEL! EQU 0 SET "perr1=0"
)
FOR /f "delims=" %%i IN ('ping -n 1 -w 1 UNKNOWN_DOMAIN') DO (
	echo %%i | find "[0.0.0.0]" >nul
	IF !ERRORLEVEL! EQU 0 SET "perr2=0"
	echo %%i | find "could not find host" >nul
	IF !ERRORLEVEL! EQU 0 SET "perr2=0"
)
FOR /f "delims=" %%i IN ('ping -n 1 -w 1 UNKNOWN_DOMAIN') DO (
	echo %%i | find "[0.0.0.0]" >nul
	IF !ERRORLEVEL! EQU 0 SET "perr3=0"
	echo %%i | find "could not find host" >nul
	IF !ERRORLEVEL! EQU 0 SET "perr3=0"
)
FOR /f "delims=" %%i IN ('ping -n 1 -w 1 UNKNOWN_DOMAIN') DO (
	echo %%i | find "[0.0.0.0]" >nul
	IF !ERRORLEVEL! EQU 0 SET "perr4=0"
	echo %%i | find "could not find host" >nul
	IF !ERRORLEVEL! EQU 0 SET "perr4=0"
)
FOR /f "delims=" %%i IN ('ping -n 1 -w 1 UNKNOWN_DOMAIN') DO (
	echo %%i | find "[0.0.0.0]" >nul
	IF !ERRORLEVEL! EQU 0 SET "perr5=0"
	echo %%i | find "could not find host" >nul
	IF !ERRORLEVEL! EQU 0 SET "perr5=0"
)

REM There's no OR operator for "IF"
SET perr=0
IF %perr1% EQU 1 SET perr=1
IF %perr2% EQU 1 SET perr=1
IF %perr3% EQU 1 SET perr=1
IF %perr4% EQU 1 SET perr=1
IF %perr5% EQU 1 SET perr=1

IF %perr% NEQ 0 (
	REM Show the message to the user
	echo ERROR: You opted to block the analytics servers but they are reachable. Please re-run the patch script. >_error.txt
	notepad _error.txt
	del _error.txt
	exit
)
REM DOMAIN_CHECK_END


REM ============= Launch the game =============
REM https://docs.unity3d.com/Manual/PlayerCommandLineArguments.html
REM Append the arguments to the command: launcher.bat arg1 arg2 ...

start /wait GenshinImpact.exe %*
